/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.shashank.platform.shotangapp;

import com.shashank.platform.shotangapp.utils.NumberUtil;
import com.shashank.platform.shotangapp.utils.ResUtils;
import junit.framework.TestCase;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.utils.Color;
import ohos.app.Context;
import org.junit.Assert;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * 项目单元测试
 */
public class AppTest extends TestCase {
    /**
     * 测试资源获取
     */
    @Test
    public void testGetColorFromRes() {
        Context appContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        Color color = ResUtils.getColorFromRes(appContext, ResourceTable.Color_purple_700);
        Assert.assertNotNull(color);
    }

    /**
     * 测试Number工具类Add
     */
    @Test
    public void testNumberAdd() {
        double result = NumberUtil.add(10, 10);
        assertThat(result, is(20.0));
    }

    /**
     * 测试Number工具类Sub
     */
    @Test
    public void testNumberSub() {
        double result = NumberUtil.sub(20, 10);
        assertThat(result, is(10.0));
    }

    /**
     * 测试Number工具类Mul
     */
    @Test
    public void testNumberMul() {
        double result = NumberUtil.mul(10, 10);
        assertThat(result, is(100.0));
    }

    /**
     * 测试Number工具类Div
     */
    @Test
    public void testNumberDiv() {
        double result = NumberUtil.div(20, 10);
        assertThat(result, is(2.0));
    }
}